<template>
	<view>
		<!-- 新闻资讯 -->
		<view class="news">
			<view class="news_item" v-for="item in news" :key="item.id" @click="XQ">
				<image :src="item.img_url"></image>
				<view class="right">
					<!-- 标题 -->
					<view class="tit">{{item.title}}</view>
					<!-- 内容 -->
					<view class="info">
						<text>发表时间:{{item.add_time | formatDate}}</text>
						<text>浏览次数:{{item.click}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		// 时间转换
		filters:{
			formatDate(date){
				const nDate =new Date(date)
				const year = nDate.getFullYear()
				const month =nDate.getMonth().toString().padStart(2,0)
				const day =nDate.getDay().toString().padStart(2,0)
				return year+"-"+month+"-"+day
			}
		},
		data() {
			return {
				news:[]
			}
		},
		onLoad() {
			this.getNews()
		},
		methods: {
			// 获取商品咨询
			async getNews(){
				const res =await this.$MyRequest({
					url:"/api/getnewslist"
				})
				console.log(res)
				this.news =res.data.message
			},
			// 获取商品详情
			getXQ(){
				
			},
			XQ(){
				uni.navigateTo({
					url:"/pages/xq/xq"
				})
				console.log(111)
			}
		}
	}
</script>

<style lang="scss">
	.news{
		.news_item{
			display: flex;
			border-bottom: 1px solid red;
			padding: 10rpx 20rpx;
			image{
				min-width: 200rpx;
				min-height: 200rpx;
				width: 200rpx;
				height: 150rpx;
			}
			.right{
				margin-left: 15rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.tit{
					font-size: 30prx;
				}
				.info{
					font-size: 24rpx;
					text:nth-child(2){
						margin-left: 30rpx;
					}
				}
			}
		}
	}
</style>
